"""
设备模块初始化
Device Module Initialization

包含所有IoT设备的实现类和工厂类
Contains implementation classes and factory class for all IoT devices
"""

from .base import BaseDevice
from .l16 import L16Device
from .s8 import S8Device

class DeviceFactory:
    """
    设备工厂类
    Device Factory Class
    
    用于根据设备类型创建对应的设备实例
    Used to create device instances based on device type
    """
    
    _device_registry = {
        'L16': L16Device,
        'S8': S8Device,
    }
    
    @classmethod
    def create_device(cls, device_type: str, device_id: str):
        """
        创建设备实例
        Create device instance
        
        Args:
            device_type (str): 设备类型 / Device type
            device_id (str): 设备ID / Device ID
            
        Returns:
            BaseDevice: 设备实例 / Device instance
            
        Raises:
            ValueError: 不支持的设备类型 / Unsupported device type
        """
        device_class = cls._device_registry.get(device_type.upper())
        if not device_class:
            raise ValueError(f"不支持的设备类型: {device_type} / Unsupported device type: {device_type}")
        
        return device_class(device_id)
    
    @classmethod
    def get_supported_devices(cls) -> list:
        """
        获取支持的设备类型列表
        Get list of supported device types
        
        Returns:
            list: 支持的设备类型 / Supported device types
        """
        return list(cls._device_registry.keys())
    
    @classmethod
    def register_device(cls, device_type: str, device_class):
        """
        注册新的设备类型
        Register new device type
        
        Args:
            device_type (str): 设备类型 / Device type
            device_class: 设备类 / Device class
        """
        cls._device_registry[device_type.upper()] = device_class

__all__ = [
    'BaseDevice',
    'L16Device', 
    'S8Device',
    'DeviceFactory'
]